<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Đặng Khánh Trung
 * Date: 10/29/12
 * Time: 9:39 AM
 * To change this template use File | Settings | File Templates.
 */
defined('_JEXEC') or die;

class VastViewChucdanhs extends JViewLegacy
{
    protected $items;
    protected $pagination;
    protected $state;
    protected $canDo;

    /**
     * Display the view
     *
     * @return    void
     */
    public function display($tpl = null)
    {
        $this->items = $this->get('Items');
        $this->pagination = $this->get('Pagination');
        $this->state = $this->get('State');

        JLoader::register('ChucdanhsHelper', JPATH_COMPONENT . '/helpers/chucdanh.php');

        $this->canDo = ChucdanhsHelper::getActions();

        // Check for errors.
        if (count($errors = $this->get('Errors'))) {
            JError::raiseError(500, implode("\n", $errors));
            return false;
        }

        $this->addToolbar();

        parent::display($tpl);
    }

    /**
     * Add the page title and toolbar.
     *
     * @since    1.6
     */
    protected function addToolbar()
    {
        $user = JFactory::getUser();

        JToolBarHelper::title(JText::_('COM_VAST_MANAGER_CHUCDANHS'), 'head vm_manufacturer_48');

        if ($this->canDo->get('vast.danhmuc.manage')) {
            JToolBarHelper::addNew('chucdanh.add', 'COM_VAST_CHUCDANH_JTOOLBAR_NEW');
        }

        if ($this->canDo->get('vast.danhmuc.manage')) {
            JToolBarHelper::editList('chucdanh.edit', 'COM_VAST_CHUCDANH_JTOOLBAR_EDIT');
        }

        if ($this->canDo->get('vast.danhmuc.manage')) {
            JToolBarHelper::deleteList('', 'chucdanh.delete', 'COM_VAST_CHUCDANH_JTOOLBAR_DELETE');            
        }

        if ($this->canDo->get('core.admin')) {
            JToolBarHelper::divider();
            JToolBarHelper::preferences('com_vast', '550', '875', 'COM_VAST_CHUCDANH_JTOOLBAR_OPTIONS');
        }

    }
}